import * as client from './client'
import urlConfig from './urlConfig'
import {Md5} from "ts-md5/dist/md5";
///游客预支付接口
/**
 * 请求参数
 */
export class TouristPayRst {
    /**
     * 壹键哥-1，壹掌柜-2，盖象商城=3，盖象优选=4
     */
    public merchantType: number;
    /**
     * 客户端类型(PC-1,APP-2,WAP(手机网站)-3)
     */
    public clientType: number;
    /**
     * 支付类型
     */
    public paymentType: number;
    /**
     * 订单号
     */
    public salesOrderCode: string;
    /**
     * 同步回调地址
     */
    public returnUrl: string;

    /**
     * 客户端IP
     */
    public clientIP: string;
    /**
     * WAP网站域名
     */
    public wapUrl: string;
    /**
     * 签名
     */
    public sign: string;

    public remark: string;
    
}

/**
 * 返回数据
 */
export class TouristPayRpn {
    public isSuccess: number;
    //状态码？
    public code: string;
    //描述
    public description: string;
    //返回数据
    public resData: rsponseData;
}
/**
 * 返回数据
 */
export class  rsponseData {
    public linkUrl: string;
    public paymentCode: string;
    public tokenID: string;
    public jsApiJson: string;
    public aliApiJson: string;
    public aliHtml: string;
}

export async function SingMD5(params: string) {
    if(params == null || params.length <= 0) return '';
    // let startCode = params.substr(0,18);
    // let endCode = params.substr(18,18);
    // let startCodeArr = startCode.split('');
    // let endCodeArr = endCode.split('');
    // let even = startCodeArr.filter((item, idx)=>{
    //     if(idx % 2 === 0) return item;
    // })
    // let odd  = endCodeArr.filter((item, idx)=>{
    //     if(idx % 2 !== 0) return item;
    // })
    let startCode = params.split("").reverse().join("");
    let secretStr = 'c0e883809070d055fed5e366c993';
    let str = startCode + secretStr + params;
    let md5Str = Md5.hashStr(str).toString()
    return md5Str
}

/**
 * 获取数据
 * @param rst 参数
 */
export async function exec(rst: TouristPayRst) {
    const data = await client.exec(urlConfig.touristPay, rst);
    return JSON.parse(data) as TouristPayRpn;
}
